/**
 * $Id: SysControlConfSyncThread.java,v 1.4 2006/06/15 13:55:06 star Exp $
 *
 * Copyright 2006 Skyinfo, Inc. All Rights Reserved.
 */
package com.haoxi.gateway.runner;

import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.haoxi.gateway.common.InitSystemControlConfig;
import com.haoxi.gateway.common.SYSConst;

/**
 * TODO
 * 
 * Revision History
 * 
 * 2006-5-30,star.Zhao,created it
 */
public class SysControlConfSyncThread implements Runnable {
    private final static Log log = LogFactory
            .getLog(SysControlConfSyncThread.class);
    private boolean running = true;
    private int delay;

    public SysControlConfSyncThread(int delay) {
        this.delay = delay;
    }

    public void run() {
        log.debug("SpecialMobileChgThread Thread start()!");
        while (running) {
            // sleep
            try {
                Thread.sleep(delay);
            } catch (InterruptedException ite) {
                log.error("InterruptedException in SysControlConfSyncThread.run()!",
                                ite);
            }

            // 实时加载系统控制参数配置
            try {
                log.debug("-------SysControlConfSyncThread Start load the system control config in real time ！-------------------");
                Map sysControlConfMap = RunnerMgr.getInstance().getSystemConf();
                synchronized (sysControlConfMap) {
                    sysControlConfMap.clear();
                    RunnerMgr.getInstance().setSystemConf(
                            InitSystemControlConfig.loadSystemControlConfig());
                }
                
                // 数据保护开关
                RunnerMgr.getInstance().setMemorydata_protect(InitSystemControlConfig.getInt(SYSConst.CONF_MEMORYDATA_PROTECT));
                //log.debug("InitSystemControlConfig.loadSystemControlConfig() load successfully, Memorydata_protect :["+InitSystemControlConfig.getInt(SYSConst.CONF_MEMORYDATA_PROTECT)+"]");
                log.debug("-------SysControlConfSyncThread load the system control config in real time successfull！-------------------");
            } catch (Throwable e) {
                log.error("-------SysControlConfSyncThread load the system control config in real time unsuccessfull！-------------------");
            }
        }
    }

}
